##Nginx安装
##安装编译环境
yum install -y  zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ make

##下载安装包
wget http://nginx.org/download/nginx-1.16.1.tar.gz

##解压目录
tar -zxvf nginx-1.16.1.tar.gz

##编译安装
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-stream --with-http_ssl_module && make && make install

##Nginx主备集群配置

##安装Keepalived
yum install keepalived -y

##修改配置
vi /etc/keepalived/keepalived.conf

	global_defs {
        router_id hostname #主机名称
	}
	vrrp_instance VI_1 {
        state MASTER 	#主机MASTER、备机BACKUP
        interface eth0  #网卡名称
        virtual_router_id 51 #路由ID 主备保持一致
        mcast_src_ip 192.168.0.100 #服务器IP
        priority 100
        advert_int 1
        authentication {
                auth_type PASS 
                auth_pass 1111
        }
        virtual _ipaddress {
         192.168.0.300 #虚拟IP
		}
	}
 
##启动keepalived
systemctl start keepalived

##RabbitMQ安装
##安装编译环境
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

##解压目录
tar -zxvf otp_src_21.3.tar.gz

##编译安装
cd otp_src_21.3
./configure --prefix=/usr/local/erlang --with-ssl --enable-threads --enable-smp-support --enable-kernel-poll --enable-hipe --without-javac && make && make install

##加入环境变量/etc/profile
ERL_PATH=/usr/local/erlang/bin
PATH=$ERL_PATH:$PATH

##安装rabbitmq
##解压目录重命名
tar -xvf rabbitmq-server-generic-unix-3.8.4.tar
mv rabbitmq-server-generic-unix-3.8.4/  rabbitmq-3.8.4

##加入环境变量/etc/profile
export RabbitMQ=/usr/local/src/rabbitmq-3.6.15
export PATH=$PATH:$RabbitMQ/sbin

##集群配置
1.替换.erlang.cookie内容两台保持一致
2.重新启动服务
./rabbitmq-server -detached
3.子节点配置
./rabbitmqctl stop_app
./rabbitmqctl join_cluster rabbit@主机名1 (主节点)
./rabbitmqctl start_app

4.主节点设置镜像策略
./rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'

##账号权限配置
./rabbitmqctl add_user hqadmin hqadmin@2020
./rabbitmqctl set_permissions -p "/" hqadmin ".*" ".*" ".*"
./rabbitmqctl set_user_tags hqadmin administrator

#集群宕机处理
1.删除var/lib/rabbitmq/mnesia/*
2.重新启动服务
3.子节点配置
./rabbitmqctl stop_app
./rabbitmqctl join_cluster rabbit@主机名1 (主节点)
./rabbitmqctl start_app
